home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / sphigs / sph_dos.lha / dos / sphdemo.v08 / main.c next >
Encoding:
C/C++ Source or Header  |  1991-11-26  |  8.4 KB  |  341 lines

  1. #include "SPHDEMO.h"
  2. #include "struct.h"
  3. #include "view.h"
  4.  
  5. /** NOTE TO READER
  6. This program was originally written on the Mac and included dialog boxes
  7. and help windows that taught the concepts of viewing.  That's why there
  8. are stubs and unused variables in this main module, which used to handle
  9. all the Mac-specific user interface widgets.
  10. **/
  11.  
  12.  
  13. static int currenderitem = 4, curchimneymenuitem = 'c';
  14. static int curgridmenuitem = 1, curvpmenuitem = 'A';
  15. static int curCamDialogID = 0;
  16.  
  17. static int curHelpDialogID = 0;
  18.  
  19.  
  20. #define rendermenuID   200
  21. #define cameramenuID   202
  22. #define chimneymenuID  201
  23. #define viewportmenuID 204
  24. #define pickmenuID     205
  25. #define gridmenuID     203
  26. #define modelmenuID    206
  27. #define applemenuID    209
  28.  
  29.  
  30.  
  31. static void InstallCameraDialog (int whichitem)
  32. {
  33.    curCamDialogID = whichitem + 300;
  34.    switch (whichitem) {
  35.     case 1:
  36.       fprintf (stderr, "You are now controlling the VRP along the UVN axes...\n");
  37.       break;
  38.     case 2:
  39.       fprintf (stderr, "You are now controlling the VRP along the XYZ axes...\n");
  40.       break;
  41.     case 3:
  42.       fprintf (stderr, "You are now controlling the VPN...\n\
  43.       You can 'yaw' (rotate about the V axis) by using the S and D keys\n\
  44.       You can 'pitch' (rotate about the U axis) by using the E and X keys\n");
  45.       break;
  46.     case 4:
  47.       fprintf (stderr, "You are now controlling the PRP...\n\
  48.       Move it towards the viewplane (reduce the focal length) using - key\n\
  49.       Move it away from the viewplane (increase focal length) using = key\n");
  50.       break;
  51.     case 5:
  52.       fprintf (stderr, "You are now controlling the Front clipping plane\n\
  53.       Use = to bring it towards eye, - to push away from eye\n");
  54.       break;
  55.     case 6:
  56.       fprintf (stderr, "You are now controlling the Back clipping plane\n\
  57.       Use = to bring it towards eye, - to push away from eye\n");
  58.       break;
  59.    }      
  60. }
  61.  
  62. static void InstallHelpDialog (int whichmenuid)
  63. {
  64. }
  65.  
  66.       
  67. static int motion_granularity = 30;
  68.          
  69. static void DisplayMotionGranularity (void)
  70. {
  71.    fprintf (stderr,  "Current motion granularity is %d\n", motion_granularity);
  72. }
  73.  
  74.  
  75.  
  76. static void AddGridInFrontOfRoot (int structID, int viewID)
  77. {
  78.    SPH_unpostRoot (structID, viewID);
  79.    SPH_postRoot (GRID_STRUCT, viewID);
  80.    SPH_postRoot (structID, viewID);
  81. }
  82.  
  83.  
  84.  
  85.  
  86. static void ChangeCameraOnAxis (int axis, double bias)
  87. {
  88.    double pitch=0.0, yaw=0.0;
  89.    switch (curCamDialogID) {
  90.     case 301:
  91.       ChangeVRP_relativeUVN (bias*motion_granularity, axis); 
  92.       break;
  93.     case 302:
  94.       ChangeVRP_relativeWC (bias*motion_granularity, axis); 
  95.       break;
  96.     case 303:
  97.       switch (axis) {
  98.        case X_AXIS: 
  99.      yaw = bias * motion_granularity; break;
  100.        case Y_AXIS: 
  101.      pitch = bias * motion_granularity; break;
  102.        default:
  103.      return;
  104.       }
  105.       ChangeVPN (pitch, yaw); 
  106.       break;
  107.     case 304:
  108.       if (axis != Z_AXIS) 
  109.      return;
  110.       ChangePRP (bias*motion_granularity);
  111.       break;
  112.     case 305:
  113.       if (axis != Z_AXIS) 
  114.      return;
  115.       ChangeFrontClipPlane (bias*motion_granularity);
  116.       break;
  117.     case 306:
  118.       if (axis != Z_AXIS) 
  119.      return;
  120.       ChangeBackClipPlane (bias*motion_granularity);
  121.       break;
  122.    }
  123.    ShowUsingNewView1 ();
  124. }
  125.  
  126.  
  127.  
  128. static void PrintCorrelationInfo (pickInformation *pinfo)
  129. {
  130.    if (pinfo->pickLevel == 4)
  131.       printf ("You picked the chimney on ");
  132.    else
  133.       printf ("You picked ");
  134.  
  135.    printf ("house #%d ", 1 + (int)((pinfo->path[1].elementIndex-1)/3));
  136.    
  137.    printf ("on street #%d.\n", 1 + (int)(pinfo->path[0].elementIndex/2));
  138. }
  139.  
  140.  
  141.  
  142. main (argc, argv)
  143. int argc;
  144. char **argv;
  145. {
  146.    double bias;
  147.    long result;
  148.    int whichmenu, whichitem, keycode;
  149.    int numplanes=7, numshades=10;
  150.    FILE *debugfile;
  151.    char buffer[100];
  152.    boolean READ_FROM_STDIN = FALSE;
  153.    locator_measure locmeas;
  154.    pickInformation pickinfo;
  155.  
  156.  
  157.    READ_FROM_STDIN = TRUE;
  158.    
  159.    /* STARTUP SPHIGS */
  160.    if (READ_FROM_STDIN) {
  161.       printf ("\nPlease enter number of framebuffer planes to allocate:\n");
  162.       scanf ("%d", &numplanes);
  163.       printf ("\nPlease enter number of shades per flexicolor:\n");
  164.       printf 
  165.      ("   (Note: this affects how many different flexicolors will be ");
  166.       printf ("available.)\n");
  167.       scanf ("%d", &numshades);
  168.    }
  169.  
  170.    SPH_begin (500,400, numplanes, numshades);
  171.  
  172.    printf ("\nThis is what I was able to provide re: colors...\n");
  173.    printf ("     Number of custom, flexible colors: %d\n", NUM_OF_FLEXICOLORS);
  174.    printf ("     Number of custom, non-flexible colors: %d\n\n", 
  175.        (NUM_OF_APPL_SETTABLE_COLORS-NUM_OF_FLEXICOLORS));
  176.    
  177.    SPH_setImplicitRegenerationMode (SUPPRESSED);
  178.  
  179.    /* We hope there are enough flexicolors for these. */
  180.    SPH_loadCommonColor (2, "yellow");
  181.    SPH_loadCommonColor (3, "green");
  182.    SPH_loadCommonColor (4, "turquoise");
  183.    SPH_loadCommonColor (5, "pink");
  184.    SPH_loadCommonColor (6, "goldenrod");
  185.    SPH_loadCommonColor (7, "firebrick");
  186.  
  187.    /* But these need not be flexicolors. */
  188.    SPH_loadCommonColor (red, "red");
  189.    SPH_loadCommonColor (grey, "lightgrey");
  190.    SPH_loadCommonColor (orange, "orange");
  191.    SPH_loadCommonColor (yellow, "yellow");
  192.    SPH_loadCommonColor (limegreen, "yellowgreen");
  193.    SPH_loadCommonColor (forestgreen, "forestgreen");
  194.    SPH_loadCommonColor (blue, "blue");
  195.    
  196.    InitAllViews();
  197.    BuildEverything ();
  198.    
  199.    DisplayAllViews ();
  200.    ShowUsingNewView1();
  201.    SPH_postRoot (NEIGHBORHOOD_STRUCT, PERSPECTIVE_VIEW);
  202.    
  203.    
  204.    /* INITIALIZE THE GRANULARITY DIALOG BOX */
  205.    DisplayMotionGranularity();
  206.    
  207.    InstallCameraDialog (2);
  208.    
  209.    SRGP_setKeyboardProcessingMode (RAW);
  210.    SRGP_setInputMode (KEYBOARD, EVENT);
  211.    SRGP_setInputMode (LOCATOR, EVENT);
  212.    
  213.  top:
  214.    SPH_setImplicitRegenerationMode (ALLOWED);
  215.  
  216.    if (READ_FROM_STDIN)
  217.       gets(buffer);
  218.    else {
  219.       switch (SRGP_waitEvent (INDEFINITE)) {
  220.        case KEYBOARD:
  221.      SRGP_getKeyboard (buffer, 2);
  222.      break;
  223.        case LOCATOR:
  224.      SPH_getLocator (&locmeas);
  225.      if (locmeas.button_chord[0] == DOWN) 
  226.         if (locmeas.view_index == PERSPECTIVE_VIEW) {
  227.            SPH_pickCorrelate 
  228.           (locmeas.position, locmeas.view_index, &pickinfo);
  229.            if (pickinfo.pickLevel > 0)
  230.           PrintCorrelationInfo (&pickinfo);
  231.         }
  232.      goto top;
  233.       }
  234.    }
  235.    
  236.    SPH_setImplicitRegenerationMode (SUPPRESSED);
  237.  
  238.    bias = 1.0;
  239.     
  240.    switch (buffer[0]) {
  241.  
  242.      case '<':
  243.        if ((motion_granularity -= 5) < 1)  motion_granularity =  1;
  244.        DisplayMotionGranularity(); 
  245.        break;
  246.  
  247.      case '>':
  248.        if ((motion_granularity += 5) > 99) motion_granularity = 99;
  249.        DisplayMotionGranularity(); 
  250.        break;
  251.  
  252.      case 'g':
  253.        sscanf (buffer, "g%d", &motion_granularity);
  254.        DisplayMotionGranularity();
  255.        break;
  256.  
  257.      case '0':
  258.        RestoreCameraToDefault ();
  259.        ShowUsingNewView1 ();
  260.        break;
  261.  
  262.      case '1':
  263.      case '2':
  264.      case '3':
  265.      case '4':
  266.      case '5':
  267.      case '6':
  268.        InstallCameraDialog (buffer[0] - '0');    
  269.        break;
  270.  
  271.      case 's':
  272.        bias = -1.0; /*nobreak*/
  273.      case 'd':
  274.        ChangeCameraOnAxis (X_AXIS, bias);
  275.        break;
  276.  
  277.      case 'x':
  278.        bias = -1.0; /*nobreak*/
  279.      case 'e':
  280.        ChangeCameraOnAxis (Y_AXIS, bias);
  281.        break;
  282.  
  283.      case '-':
  284.        bias = -1.0; /*nobreak*/
  285.      case '=':
  286.        ChangeCameraOnAxis (Z_AXIS, bias);
  287.        break;
  288.  
  289.      case 'C':
  290.      case 'c':
  291.        if (buffer[0] == curchimneymenuitem)
  292.       break;
  293.        if (buffer[0] == 'C') {
  294.       AddChimneyToHouse (HOUSE_STRUCT);
  295.       AddChimneyToHouse (FAKE_HOUSE_TOP_STRUCT);
  296.       AddChimneyToHouse (FAKE_HOUSE_SIDE_STRUCT);
  297.        }
  298.        else {
  299.       TakeChimneyFromHouse (HOUSE_STRUCT);
  300.       TakeChimneyFromHouse (FAKE_HOUSE_TOP_STRUCT);
  301.       TakeChimneyFromHouse (FAKE_HOUSE_SIDE_STRUCT);
  302.        }
  303.        curchimneymenuitem = buffer[0];
  304.        break;
  305.  
  306.      case 'a':
  307.      case 'A':
  308.        if (buffer[0] == curvpmenuitem)
  309.       break; 
  310.        SPH_setImplicitRegenerationMode (SUPPRESSED);
  311.        if (buffer[0] == 'a')
  312.       DisplayOnlyFullRenderView();
  313.        else
  314.       DisplayAllViews();
  315.        ShowUsingNewView1();
  316.        SPH_setImplicitRegenerationMode (ALLOWED);
  317.        curvpmenuitem = buffer[0];
  318.        break;
  319.  
  320.      case 'n':
  321.      case 'N':
  322.        SPH_setRenderingMode (PERSPECTIVE_VIEW, LIT_FLAT); break;
  323.  
  324.      case 'm':
  325.      case 'M':
  326.        SPH_setRenderingMode (PERSPECTIVE_VIEW, WIREFRAME); break;
  327.  
  328.      case '}':
  329.        /* Undocumented */
  330.        ChangePRPforOrtho();
  331.        ShowUsingNewView1 ();
  332.        break;
  333.      case '{':
  334.        /* Undocumented */
  335.        ChangePRPforClosestPerspective();
  336.        ShowUsingNewView1 ();
  337.        break;
  338.     }
  339.    goto top;
  340. }
  341.